<?php
require_once(dirname(__FILE__)."/Request/RequestClient.php");
require_once(dirname(__FILE__)."/Request/RequestServer.php");
require_once(dirname(__FILE__)."/Request/RequestPage.php");
require_once(dirname(__FILE__)."/Request/Parameters/RequestHeaders.php");
require_once(dirname(__FILE__)."/Request/Parameters/RequestParametersGet.php");
require_once(dirname(__FILE__)."/Request/Parameters/RequestParametersPost.php");
require_once(dirname(__FILE__)."/Request/Parameters/RequestParametersFiles.php");

/**
 * Detects information about request from $_SERVER, $_GET, $_POST, $_FILES. Normally, these parameters need not be changed.
 */
class Request {
	public $client;		// identifies client machine
	public $server;		// identifies server machine
	public $page;		// page requested by client
	
	public $headers;	// parameters set by browser
	public $get;		// parameters set by client in QUERY_STRING
	public $post;		// parameters set by client in POST
	public $files;		// parameters set by client in multipart files
	
	/**
	 * Detects all aspects of a request.
	 */
	public function __construct() {
		$this->client  	= new RequestClient();
		$this->server 	= new RequestServer();
		$this->page		= new RequestPage();
		$this->headers	= new RequestHeaders();
		$this->get		= new RequestParametersGet();
		$this->post		= new RequestParametersPost();
		$this->files	= new RequestParametersFiles();
	}
	
	/**
	 * Gets input stream contents.
	 * 
	 * @return binary
	 */
	public function getInputStream() {
		return file_get_contents("php://input");
	} 

	/**
	 * Outputs collected information as associative array.
	 *
	 * @return array
	 */
	public function toArray() {
		$tblOutput = array();
		$tblOutput['client'] 	= $this->client->toArray();
		$tblOutput['server'] 	= $this->server->toArray();
		$tblOutput['page'] 		= $this->page->toArray();
		$tblOutput['headers'] 	= $this->headers->toArray();
		$tblOutput['get'] 		= $this->get->toArray();
		$tblOutput['post']		= $this->post->toArray();
		$tblOutput['files']		= $this->files->toArray();
		return $tblOutput;
	}
}